package com.wlc.thread;

import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author 王立朝
 * @date 2022/4/15
 * @description:
 */
public class ThreadAndRunnableDemo {

    public void test01(){

    }

    public static void main(String[] args) {
        new MyThread().start();// ticket 张数为5
        new MyThread().start();// ticket 张数为5
        System.out.println("------------");
        MyThread2 t2 = new MyThread2();

        new Thread(t2).start();
        new Thread(t2).start();
    }

    static class MyThread extends Thread {
        private int ticket = 5;

        @Override
        public  void run() {
            while (true) {

                System.out.println("ticket剩余张数" + ticket--);
                if (ticket < 0) {
                    break;
                }
            }

        }
    }

    static class MyThread2 implements Runnable{
        private int ticket = 5;
        @Override
        public void run() {
            while (true) {

                System.out.println("ticket2剩余张数" + ticket--);
                if (ticket == 0) {
                    break;
                }
            }
        }
    }
}

